import random
import sys
coin = 5000
def playGame():
    global coin
    guess = int(input("请输入你猜的数字："))
    num = random.randint(0, 100)
    while coin > 0:
        if guess == num:
                print("你猜对了")
                coin = coin + 3000
                print("你的金币余额为：",coin)
                break
        elif guess > num:
            print("猜大了")
            coin = coin - 500
            print(coin)
            guess = int(input("请输入你猜的数字："))
        else:
            print("猜小了")
            coin = coin - 500
            print(coin)
            guess = int(input("请输入你猜的数字："))
    else:
        print("金币不足")
        sys.exit()
if __name__ == '__main__':
    print("欢迎来到猜数字游戏")
    while True:
        playGame()
        continue_game = input("是否继续游戏？(输入'y'继续，其他任意键退出)")
        if continue_game.lower() != 'y':
            print("游戏结束，最终金币余额",coin)
            break




